/* ----------------------------- Noble Steed Engine----------------------------*
Authors : Daniel Randle
Date Created : Aug 20 2013

File:
	nsboundingbox.h

Description:
	This file contains the NSBoundinBox class which is the bounding box for objects in the game
*---------------------------------------------------------------------------*/

#ifndef NSBOUNDINBOX_H
#define NSBOUNDINBOX_H

/* ---------------------------------Class NSBoundingBox-----------------------------*

Description:
	NSBoundingBox will provide a class for the game reference object's boudning boxes

*-------------------------------------------------------------------------------*/

// includes
#include <myGL\glew.h>
#include <vector>
#include <nsmath3d.h>
#include <global.h>

class NSMesh;

class NSBoundingBox
{
public:
	struct Distances
	{
		NSVec3Df positive;
		NSVec3Df negative;
	};

	enum Type {
		OBB,
		AABB };

	NSBoundingBox(Type type=OBB);
	~NSBoundingBox();

	void calculate(const NSMesh * mesh, const NSMatrix4Df & transform = NSMatrix4Df());
	void draw(const NSMatrix4Df & transform = NSMatrix4Df());

	Distances getDistancesFromPoint(const NSVec3Df & point);

	Type getType();

	void setType(Type type);

	void update(const NSMesh * mesh, const NSMatrix4Df & transform = NSMatrix4Df());

private:
	void _calculateOBB(const NSMesh * mesh);
	void _calculateAABB(const NSMesh * mesh, const NSMatrix4Df & transform);
	void _populateVerts();
	void _drawOBB(const NSMatrix4Df & transform);
	void _drawAABB();

	NSVec3Df minCoords;
	NSVec3Df maxCoords;

	Type boxType;

	GLuint positionBuf;
	GLuint transformBuf;
	std::vector<NSVec3Df> verts;
};

#endif